package com.kun.springbootorder.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class RabbitMqConfig {

    //1. 设置交换机
    @Bean
    public FanoutExchange orderExchange() {
        return new FanoutExchange("order_fanout_exchange");
    }

    //2. 设置队列
    @Bean
    public Queue orderQueue() {
        Map<String, Object> map = new HashMap<>();
        map.put("x-dead-letter-exchange", "dead-letter-exchange");
        return new Queue("order_queue_1", true, false, false, map);
    }

    //3. 将队列绑定到交换机
    @Bean
    public Binding orderBinding(){
        return BindingBuilder.bind(orderQueue()).to(orderExchange());
    }



}
